package com.xd.springboot.config;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJcaListenerContainerFactory;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;
import javax.jms.Destination;


@Configuration
public class MQConfig {
    public static final String TOPIC_NAME ="activemq.topic";
    public  static  final  String QUEUE_NEME = "activemq.queue";
    @Bean
    public Destination topic() {return new ActiveMQTopic(TOPIC_NAME);}
    @Bean
    public Destination queue() {return new ActiveMQQueue(QUEUE_NEME);}
    @Bean
    public JmsListenerContainerFactory topicListenerContainer(ConnectionFactory connectionFactory)
    {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        // 相当于在application.yml中配置：spring.jms.pub-sub-domain=true
        factory.setPubSubDomain(true);
        return factory;
    }
}
